package com.demo.java.spring.ioc;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MyClassPathXmlApplicationContext extends ClassPathXmlApplicationContext {
    public MyClassPathXmlApplicationContext(String ...configLocations) {
        super(configLocations);
    }

    @Override
    protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
        super.postProcessBeanFactory(beanFactory);
        System.out.println("post process bean factory");
    }

    @Override
    protected void initPropertySources() {
        super.initPropertySources();
        // 子类扩展，比如：自定义环境变量或系统变量，环境变量检查，输入参数变量检查等
        System.out.println("init property sources");
    }

    @Override
    protected void customizeBeanFactory(DefaultListableBeanFactory beanFactory) {
        System.out.println("customize bean factory");
        this.setAllowBeanDefinitionOverriding(true);
        this.setAllowCircularReferences(true);
//        this.getEnvironment().getSystemEnvironment().put("hello", "world");
//        this.getEnvironment().setRequiredProperties("hello");
        super.customizeBeanFactory(beanFactory);
    }
}
